package com.example.dormmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.dormmanage.entity.Student;
import com.example.dormmanage.service.impl.BuildingService;
import com.example.dormmanage.service.impl.StudentService;
import com.example.dormmanage.view.BuildingDto;
import com.example.dormmanage.view.ResultView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/student")
@Api(tags = "学生管理")
@Slf4j
public class StudentManageController {

    @Autowired
    private StudentService studentService;

    @GetMapping
    @ApiOperation("查询学生列表")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "buildingId", value = "楼宇id", required = true,dataTypeClass = Integer.class),
                    @ApiImplicitParam(name = "page", value = "页码", required = true,dataTypeClass = Integer.class ),
                    @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true,dataTypeClass = Integer.class),
                    @ApiImplicitParam(name = "name", value = "学生姓名", required = false,dataTypeClass = String.class)
            }
    )
    public ResultView<Page> selectStudentList(Integer buildingId, Integer page, Integer pageSize, String name) {
        log.info("buildingId = {},page = {},pageSize = {},name = {}",buildingId,page,pageSize,name);
        return studentService.selectStudentList(buildingId, page, pageSize, name);
    }

    @PostMapping()
    @ApiOperation("新增学生")
    public ResultView<String> addStudentData(@RequestBody Student student){
        log.info(student.toString());
        return studentService.addStudentData(student);
    }

    @DeleteMapping()
    @ApiOperation("删除学生")
    public ResultView<String> deleteStudentData(Long id){
        return studentService.deleteStudentData(id);
    }

}
